package com.yyysj.system.controller;

import com.yyysj.common.core.constants.HttpConstants;
import com.yyysj.common.core.domain.Result;
import com.yyysj.system.domain.dto.LoginDTO;
import com.yyysj.system.domain.dto.LogonDTO;
import com.yyysj.system.domain.dto.SysUserSaveDTO;
import com.yyysj.common.core.domain.LoginUserVO;
import com.yyysj.system.domain.vo.SysUserVO;
import com.yyysj.system.service.ISysUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/sysUser")
@RequiredArgsConstructor
@RestController
@Tag(name = "管理员接口")
public class SysUserController {

    private final ISysUserService sysUserService;

    @Operation(summary = "管理员登录", description = "根据账号密码进行管理员登录")
    @PostMapping("/login")
    public Result<String> login(@RequestBody LoginDTO loginDTO) {
        return sysUserService.login(loginDTO.getUserAccount(), loginDTO.getPassword());
    }

    @Operation(summary = "管理员注册", description = "管理端用户注册")
    @PostMapping("/logon")
    public Result<?> logon(@RequestBody LogonDTO logonDTO) {
        return Result.build(sysUserService.logon(logonDTO));
    }

    @Operation(summary = "退出登录", description = "根据前端发送的token来进行管理员退出登录")
    @DeleteMapping("/logout")
    public Result<?> logout(@RequestHeader(HttpConstants.AUTHENTICATION) String token) {
        return sysUserService.logout(token);
    }

    @Operation(summary = "新增管理员", description = "根据账号密码进行管理员注册")
    @PostMapping("/add")
    public Result<?> add(@RequestBody SysUserSaveDTO sysUserSaveDTO) {
        return sysUserService.save(sysUserSaveDTO);

    }

    @Operation(summary = "管理员信息", description = "根据前端发送的token来获取管理员信息")
    @GetMapping("/info")
    public Result<LoginUserVO> info(@RequestHeader(HttpConstants.AUTHENTICATION) String token) {
        return sysUserService.info(token);
    }

    @DeleteMapping("/{userId}")
    @Operation(summary = "删除用户", description = "通过用户id删除用户")
    @Parameters(value = {
            @Parameter(name = "userId", in = ParameterIn.PATH, description = "用户ID")
    })
    @ApiResponse(responseCode = "1000", description = "成功删除用户")
    @ApiResponse(responseCode = "2000", description = "服务繁忙请稍后重试")
    @ApiResponse(responseCode = "3101", description = "用户不存在")
    public Result<Void> delete(@PathVariable Long userId) {
        return null;
    }

    @Operation(summary = "用户详情", description = "根据查询条件查询用户详情")
    @GetMapping("/detail")
    @Parameters(value = {
            @Parameter(name = "userId", in = ParameterIn.QUERY, description = "用户ID"),
            @Parameter(name = "sex", in = ParameterIn.QUERY, description = "用户性别")
    })
    @ApiResponse(responseCode = "1000", description = "成功获取用户信息")
    @ApiResponse(responseCode = "2000", description = "服务繁忙请稍后重试")
    @ApiResponse(responseCode = "3101", description = "用户不存在")
    public Result<SysUserVO> detail(@RequestParam(required = true) Long userId, @RequestParam(required = false) String sex) {
        return null;
    }
}

